<?php

namespace app\admin\model\activtyc;

use think\Model;
use think\Cache;
use app\admin\model\Area;
class Round extends Model
{
    // 表名
    protected $name = 'activity_round';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'school_text',
        'book_text',
        'volume_text',
    ];
    

    public function getProvinceOrderList()
    {
        if(!$list = Cache::get('arealist'))
        {
            $area = Area::field('id,name')->select();
            $area = collection($area)->toArray();
            $list = array_column($area,'name','id');
            Cache::set('areaList',$list,0);//设置0永久缓存不过期
        }
        return $list;
    }
    public function getSchoolTextAttr($value, $data)
    {
        $value = isset($data['school_id']) ? $data['school_id'] : '';
        return $value ? TableField('School_B','name',$value):'';
    } 
    public function getVolumeTextAttr($value, $data)
    {
        $value = isset($data['volume_id']) ? $data['volume_id'] : '';
        return $value ? TableField('Volume','name',$value):'';
    } 
    public function getBookTextAttr($value, $data)
    {   
        if($data['type_school']  == 1){
            $book_id = TableField('VolumeSchool','book_id',$data['this_school']);
        }else{
            $book_id = TableField('School_B','book_id',$data['school_id']);
        }
        $value = isset($book_id) ? $book_id : '';
        return $value ? GetExplode(explode(',',$value),'Book'):'';
    }





}
